'use strict';

angular.module('afasApp')
.filter('makeBold', [function () {
  return function (input, query) {
    return input.replace(new RegExp('('+ query + ')', 'gi'), '<strong>$1</strong>');
  };
}])
.filter('repComma', [function () {
  return function (input) {
    return input.replace(/,/g,'<br>');
  };
}])
.filter('utc', function(){
  return function(val){
    var date = new Date(val);
    return new Date(date.getUTCFullYear(),
     date.getUTCMonth(),
     date.getUTCDate(),
     date.getUTCHours(),
     date.getUTCMinutes(),
     date.getUTCSeconds());
  };
})
.filter('property', [function () {
  function parseString(input){
    return input.split(".");
  }

  function getValue(element, propertyArray){
    var value = element;

    _.forEach(propertyArray, function(property){
      value = value[property];
    });

    return value;
  }

  return function (array, propertyString, target){
    var properties = parseString(propertyString);

    return _.filter(array, function(item){
      return getValue(item, properties) == target;
    });
  }
}]);